package com.glela.goods.dao.impl;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.glela.goods.dao.LimitTimeSaleDetailDao;
import com.glela.goods.mapper.LimitTimeSaleDetailMapper;
import com.glela.goods.model.LimitTimeSaleDetail;

@Repository
public class LimitTimeSaleDetailDaoImpl implements LimitTimeSaleDetailDao {
	@Autowired
	private LimitTimeSaleDetailMapper limitTimeSaleDetailMapper;

	@Override
	public LimitTimeSaleDetail selectByProductId(long productId, Date time) {
		if (productId <= 0 || time == null) {
			return null;
		}
		Map<String, Object> _query_limit_sale_detail = new HashMap<String, Object>();
		_query_limit_sale_detail.put("current_time", time);
		_query_limit_sale_detail.put("sku_no", productId);
		return limitTimeSaleDetailMapper.selectByProductId(_query_limit_sale_detail);
	}

	@Override
	public List<LimitTimeSaleDetail> selectByProductIds(Set<Long> productIds, Date nowTime) {
		return limitTimeSaleDetailMapper.selectByProductIds(productIds, nowTime);
	}

	@Override
	public List<LimitTimeSaleDetail> selectByGoodsId(long goodsId, Date time) {
		if (goodsId <= 0 || time == null) {
			return null;
		}
		Map<String, Object> _query_limit_sale_detail = new HashMap<String, Object>();
		_query_limit_sale_detail.put("current_time", time);
		_query_limit_sale_detail.put("product_sn", goodsId);
		return limitTimeSaleDetailMapper.selectByGoodsId(_query_limit_sale_detail);
	}

	@Override
	public List<LimitTimeSaleDetail> selectByGoodsIds(Collection<Long> goodsIds, Date time) {
		if (CollectionUtils.isEmpty(goodsIds) || time == null) {
			return null;
		}
		return limitTimeSaleDetailMapper.selectByGoodsIds(goodsIds, time);
	}
}